package com.hllxd.hism.star.basic.service.controller2;

import com.hllxd.hism.framework.httprpc.service.*;
import com.hllxd.hism.star.basic.service.exception.BusinessException;
import com.hllxd.hism.star.basic.service.model.doris.DPExecuteLog;
import com.hllxd.hism.star.basic.service.service.ai.DPExecuteLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author wuguangxi
 * @Description
 * @Date 2024/5/10 15:36
 */
@Slf4j
@RestGrpcService
@RestGrpcMapping("/v1/dp_execute_log")
public class DPExecuteLogController {

    @Autowired
    private DPExecuteLogService service;

    @RestGrpcMapping("/findByTableNameAndDt.do")
    public NTSTATUS findByTableNameAndDt(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            DPExecuteLog p = params.driverObject(DPExecuteLog.class);
            List<DPExecuteLog> items = service.findByTableNameAndDt(p.getTableName(), p.getDt());
            log.info("items: {}.", items.size());
            result.setData(items);
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }


    @RestGrpcMapping("/findOneByUniqueId.do")
    public NTSTATUS findOneByUniqueId(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            DPExecuteLog p = params.driverObject(DPExecuteLog.class);
            DPExecuteLog item = service.findOneByUniqueId(p.getUniqueId());
            result.setData(item);
            return NTSTATUS.SUCCESS_STATUS();
        } catch (BusinessException e) {
            log.warn("Exception: {}. {}", e, params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        } catch (Exception e) {
            log.error("Exception: {}. {}", e, params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }

}
